package com.hucheng.user.entity;

import com.hucheng.user.dto.UserDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-04-24
 * @Description: 持久层数据
 **/
@Data
public class UserDO {
    private Integer userId;
    private String username;
    private String password;
    private String nickname;
    private String salt;
    private String head;
    private Date registerDate;
    private Date lastLoginDate;
    private Integer loginCount;
    private Timestamp userDateCreated;
    private Timestamp userDateUpdated;


    public static UserDO buildUserDO(final UserDTO userDTO) {
        if (userDTO != null) {
            UserDO userDO = new UserDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(userDTO.getUserId()+"")) {
                userDO.setUserId(userDTO.getUserId());
                userDO.setUserDateCreated(currentTime);
            }else{
                userDO.setUsername(userDTO.getUsername());
                userDO.setUserDateUpdated(currentTime);
            }
            userDO.setPassword(userDTO.getPassword());
            return userDO;
        }
        return null;
    }
}
